<template>
  <div class="contain">
    <div class="headerAbs" v-show="showAbs">
      <router-link to="/">
        <div class="header-left iconfont icon-fanhui"></div>
      </router-link>
    </div>
    <div class="headerFixed" v-show="!showAbs" :style="opacityStyle">
      <router-link to="/">
        <div class="header-left iconfont icon-fanhui"></div>
      </router-link>景点详情
    </div>
  </div>
</template>
<script>
export default {
  name: "DetailHeader",
  data() {
    return {
      showAbs: true,
      opacityStyle: {
        opacity: 0,
      },
    };
  },
  methods: {
    handleShowChange() {
      const scrollTop = document.documentElement.scrollTop;
      if (scrollTop > 45) {
        this.showAbs = false;
        let opacity = scrollTop / 140;
        this.opacityStyle.opacity = opacity > 1 ? 1 : opacity;
      } else {
        this.showAbs = true;
      }
      console.log('showAbs'+this.showAbs);
    },
  },
  activated() {
    window.addEventListener("scroll", this.handleShowChange);
  },
  deactivated() {
    window.removeEventListener("scroll", this.handleShowChange);
  }
};
</script>

<style lang="stylus" scoped>
@import '~style/varibles.styl'

.contain
  // position relative
  .headerAbs
    position absolute
    top 0.1rem
    left 0.2rem
    width 0.8rem
    height 0.8rem
    line-height 0.8rem
    border-radius 0.4rem
    background-color rgba(0, 0, 0, 0.8)

    .header-left
      color #ffffff
      text-align center

  .headerFixed
    z-index 10
    overflow hidden
    position fixed
    top 0
    left 0
    right 0
    text-align center
    line-height $headerHight
    height $headerHight
    background $bgColor
    color #fff

    .iconsize
      text-align center
      font-size 0.32rem

    .header-left
      float left
      width 0.64rem
      text-align center
      font-size 0.32rem
      color #fff
</style>